package com.dengyin2000.javaeye.ordering.action;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.framework.HibernateEntityQuery;

import com.dengyin2000.javaeye.ordering.entity.SnackShop;

@Name("snackShopListAction")
public class SnackShopListAction extends HibernateEntityQuery {
	
	private static final long serialVersionUID = 7417671619941725501L;
	
	public static final String RESTRICTION = "lower(s.name) like lower( concat(#{exampleSnackShop.name},'%') )";
	
	@In(create=true)
	@Out
	private SnackShop exampleSnackShop;
	
	@Override
	public String getEjbql() {
		return "select s from SnackShop s";
	}
	
	@Override
	public String getOrder() {
		return "name";
	}
	
	@Override
	public Integer getMaxResults() {
		return 15;
	}
	
	@Override
	protected String getPersistenceContextName() {
		return "orderingDatabase";
	}
	
	@Override
	public List<String> getRestrictions() {
		if (StringUtils.isNotBlank(exampleSnackShop.getName())){
			super.getRestrictions().clear();
			super.getRestrictions().add(RESTRICTION);
		}
		return super.getRestrictions();
	}

	public SnackShop getExampleSnackShop() {
		return exampleSnackShop;
	}

	public void setExampleSnackShop(SnackShop exampleSnackShop) {
		this.exampleSnackShop = exampleSnackShop;
	}
}
